package com.ruoyi.base.filter;

import com.dyun.tool.mybatis.util.MPContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import javax.servlet.*;

/**
 * @author dyun
 */
@Slf4j
public class TenantReqFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) {
        try {
            // 前端用户,根据二级域名得到租户数据
            String domain = request.getServerName();
            if (!ObjectUtils.isEmpty(domain)) {
                // TODO 操作租户的一些数据，比如短信签名等
                // MPContextHolder.setTenantId(tenantId);
            }
            filterChain.doFilter(request, response);
        } catch (Exception e) {
            log.info(e.getMessage());
        } finally {
            MPContextHolder.clear();
        }
    }

    @Override
    public void destroy() {

    }
}
